package com.example.hydropowermanage.controller;

import com.example.hydropowermanage.pojo.Message;
import com.example.hydropowermanage.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("")
public class MessageController {
    private static final Logger logger = LoggerFactory.getLogger(MessageController.class);

    @Autowired
    private MessageService messageService;
    //获取全部普通用户消息


    // 发送消息
    @PostMapping("/send")
    public ResponseEntity<String> sendNotification(@RequestParam String sender, @RequestParam String receiver, @RequestParam String content) {
        messageService.sendNotification(sender, receiver, content);
        return ResponseEntity.ok("发送成功");
    }

    // 获取用户消息列表
    @GetMapping("/user/{username}")
    public List<Message> getUserMessages(@PathVariable String username) {
        return messageService.getUserMessages(username);
    }

    // 标记消息为已读
    @PostMapping("/mark-as-read")
    public void markMessageAsRead(@RequestParam("messageId") Long messageId) {
        messageService.markMessageAsRead(messageId);
    }

    // 删除消息
    @DeleteMapping("/{messageId}")
    public void deleteMessage(@PathVariable Long messageId) {
        messageService.deleteMessage(messageId);
    }
}
